


class CallableGenerator(object):
    def __init__(self):
        self.generator = None
        
    def function(self):
        raise NotImplementedError()
        
    def __call__(self):
        if self.generator == None:
            self.generator = self.function()
        try:
            return self.generator.next()
        except StopIteration:
            self.generator = None
            return None
            

class Generate10(CallableGenerator):
    def function(self):
        for i in range(0, 10):
            yield i
        
g = Generate10()

# Run it once
while True:
    nextValue = g()
    if nextValue == None:
        break
    print nextValue
    
# Run it again
while True:
    nextValue = g()
    if nextValue == None:
        break
    print nextValue
